Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
This change is in between a bug fix and a new feature.
We're currently using
flutter_cache_manager
throughcached_network_image
. We observe the following scenario in the crash logs:We can't tell how the DB got corrupted, but we know it happens mostly on iOS devices. This makes sense as according to sqflite docs:
Why would fixing a DB corruption make sense in the library? The problem is that once the DB gets corrupted, there cache is not functional for the user. All update/insert operations fail and there's no indication that something is wrong when
open()
is called on theCacheObjectProvider
. There's no easy way to recover from this scenario, especially in use cases such ascached_network_image
.🆕 What is the new behavior (if this is a feature change)?
When the db is opened, the additional
pragma integrity_check
(reference) query is run. If the db is corrupted, it drops the file before the db connection is opened, thus allowing the cache to "recover" from the failed state.The obvious drawback of this approach is that the binary cache contents are not wiped. I will happily accept pointers on how to resolve this and other potential issues.
💥 Does this PR introduce a breaking change?
No.
🐛 Recommendations for testing
The way I tested this on
iOS simulator
(onmacOS
):Navigate
>Reveal in Project Navigator
from the top bar.Open As
>Hex File
.At point 8. the library with no patch applied will stop caching any files.
📝 Links to relevant issues/docs
sqflite
on handling corruption - docspragma integrity_check
from SQLite - docs🤔 Checklist before submitting